package org.liang.job.repository;

import java.util.List;
import java.util.Map;

import org.springframework.stereotype.Repository;

/**
 * 任务组数据库操作类.
 * 
 * <pre>
 * 提供基本的增删改查行为
 * </pre>
 *
 * @author L.Yang
 * @version 1.0, 2015年10月9日
 */
@Repository("jobGroupRepository")
public class JobGroupRepository extends GroupRepository {


    @Override
    public boolean hasReference(String id) {
        String sql = "select * from TASK_AUTO_JOB t where t.GROUP_ID = ?";
        List<Map<String, Object>> datas = getJdbcTemplate().queryForList(sql, id);
        return (datas != null && !datas.isEmpty());
    }

    @Override
    public List<String> filterReferences(List<String> ids) {
        String sql = "select distinct j.GROUP_ID from TASK_AUTO_JOB j where j.GROUP_ID in "
                     + buildPreparedStatement4Args(ids.size());
        return getJdbcTemplate().queryForList(sql, String.class, ids.toArray());
    }

    @Override
    protected String getTableName() {
        return "TASK_JOB_GROUP";
    }
}
